<template>
<div class="shop-list">
    <div class="box column dy">
        <div class="box lr header">
            <div class="box hc content">
                <a href="index.php">
                    <div class="back box hc">
                        <img class="back-icon" src="./img/vector.png" />
                    </div>
                </a>
                <div class="box vc title-text">
                    <div :class="['nav',{'active':item.checked}]" v-for="item in typeList" :key="item.poiid" @click="changeList(item)">
                        <span>{{item.name}}</span>
                        <img src="./img/bg_icon.png" class="bg-icon" alt="" v-if="item.checked">
                    </div>
                </div>
                <a :href="'myMessage.php?pid=' + pid">
                    <div class="back box hc r" style="position: relative">
                        <img class="chat" src="./img/chat.png" />
                        <template v-if="message_count > 0">
                            <div class="box hc vc red-notice" v-if="message_count < 100">
                                {{ message_count }}
                            </div>
                            <div class="box hc vc red-notice" v-else>99+</div>
                        </template>
                    </div>
                </a>
            </div>
        </div>
        <div class="top-background"></div>
        <div class="my-container box column full">
            <div class="box vc">
                <div class="box hs notice">
                    <img src="./img/info.png" class="info" />
                    <a class="notice-text" href="meituan_help.php">
                        为防止打印机漏单，请关闭商家PC客户端自动接单
                        【点击查看关闭方法>>】
                    </a>
                </div>
            </div>
            <div class="content box full" :class="{ empty: !shops.length }">
                <!--店铺列表-->
                <div class="box column full" style="padding: 0px 10px" v-if="shops.length > 0">
                    <div class="box column shopitem" v-for="(item, index) in shops" :key="index">
                        <div class="item" v-if="item.showStatus">
                            <em class="discount-icon" v-show="!item.poiid&&item.buy_type == 3">优惠服务</em>
                            <div class="box lr sh">
                                <img class="shop-img" :src="!!item.shopimg?item.shopimg:require('./img/meituan-shop.png')" />
                                <div class="box column full img-right">
                                    <div :class="['shopname',{red:!item.poiid}]">{{ item.shopname }}</div>
                                    <div class="box hc use-p">
                                        <!-- 显示状态 -->
                                        <div :class="['use',serverStatus(item).class]">{{serverStatus(item).text}}</div>
                                        <div :class="['expire-time',{'red':fastExpiration(item)}]" v-if="item.expire_time != '0' && item.expire_time && item.poiid && item.is_white == 0">
                                            <span v-if="item.is_stop_service!=1">({{ item.expire_time | formatDate }}到期)</span>
                                            <span v-else>({{ item.switch_service | formatDate }}到期)</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- 提示状态 -->
                            <div class="item-tips" v-show="tipsStatus(item).text !=''">
                                <a :class="tipsStatus(item).class" :href="tipsStatus(item).href">{{tipsStatus(item).text}}</a>
                            </div>
                            <!-- 接单状态 -->
                            <div class="box lr hc full status" v-if="item.poiid">
                                <div class="status-now">接单状态</div>
                                <a href="javascript:void(0);" @click="showSet(item, 'list')" class="box hc full">
                                    <div class="box hc full">
                                        <div :class="orderReceiving(item).class">
                                            {{orderReceiving(item).text}}
                                        </div>
                                    </div>
                                    <img class="into" src="./img/right.png" />
                                </a>
                            </div>
                            <!-- 按钮状态 -->
                            <div class="box hc r bottom-btn notPoiid" v-if="!item.poiid && item.is_shenhe != 3">
                                <a href="javascript:void(0);" @click="notPoiid(item)">
                                    <div class='box vc hc shop-btn active'>授权店铺</div>
                                </a>
                            </div>
                            <!-- <div class="box hc r bottom-btn notPoiid" v-else-if="item.set_sn_service > 0 && !out_date(item.expire_time) && item.is_shenhe != 3">
                                <a href="javascript:void(0);" @click="selectMeal(item)">
                                    <span class='box vc hc shop-btn active'>选择服务套餐</span>
                                </a>
                            </div> -->
                            <div class="box hc r bottom-btn" v-else-if="item.poiid || item.is_shenhe==3 || (out_date(item.expire_time) && item.expire_time>0)">
                                <a class="box vc hc shop-btn" @click="selectMeal(item)" v-if="item.set_sn_service > 0 && !out_date(item.expire_time) && item.is_shenhe != 3">
                                    硬件服务
                                </a>
                                <a class="box vc hc shop-btn" :href="`buyRecord.php?pid=${item.pid}&epoid=${item.shopid}&sid=${item.sid}`" v-if="item.is_white!=1&&item.is_stop_service!=1">
                                    服务记录
                                </a>
                                <a :href="item.isWhiteHref" v-if="item.is_white >= 1 || (item.is_shenhe == 3 && !out_date(item.expire_time))" class="box vc hc shop-btn active">
                                    重新授权
                                </a>
                                <a :href="isRenew(item)" :class="['box vc hc shop-btn',{active:out_date(item.expire_time)||fastExpiration(item)}]" v-if="openBtnStatus(item)">
                                    {{item.is_shenhe!=3?'续费服务':'开通服务'}}
                                </a>
                                <a :href="`addShop.php?pro=1&sid=${item.sid}&pid=${item.pid}`" class="box vc hc shop-btn">
                                    票据设置
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
                <!--空店铺-->
                <div class="box full vc hc column empty-block" v-else>
                    <img src="./img/empty.png" class="empty-shop" />
                    <a href="buyService.php">
                        <div class="empty-text">
                            暂无店铺信息，<span class="empty-add">去添加 >></span>
                        </div>
                    </a>
                </div>
            </div>
        </div>
        <div class="bar box hc lr" v-if="tips">
            <div class="bar-text">打印机安装过程中有任何疑问，请点击查看教程！</div>
            <img src="./img/close.png" class="close" @click="close_tips()" />
            <img class="drop" src="./img/drop.png" />
        </div>
        <div class="box lr hc foot">
            <a href="https://mp.weixin.qq.com/mp/homepage?__biz=MzI0MTcxNzE5OQ==&hid=7&sn=121698bfcc0a4554a10cc4d1e345aca2">
                <div class="foot-left">查看安装教程</div>
            </a>
            <a href="buyService.php">
                <div class="foot-right">添加店铺</div>
            </a>
        </div>
    </div>
    <loading v-if="isLoading"></loading>
    <Dialog v-if="isDialog" @confirm="confirm" @close="close" :config="dialogConfig">
        <div class="consult-pop" v-if="consultPop">
            <div class="consult-pop-title">
                <img src="./img/l_vector.png" alt="">
                <span>客服号码已复制</span>
            </div>
            <p>服务详情请联系客服/售后</p>
            <p><em>{{phone}}</em> </p>
            <!-- <p class="wx-bg"><img src="./img/wx_icon.png" alt=""><span>可添加微信</span></p> -->
        </div>
    </Dialog>
    <!-- 打印机设置 -->
    <van-popup v-model="showVan" position="bottom" round closeable :style="{ height: '40%' }">
        <div class="order-setting">
            <div class="title">接单设置</div>
            <ul>
                <li v-for="(item, index) in setList" :key="index" :class="{ active: item.printtype == printtype }" @click="showSet(item, 'pop')">
                    <span class="name">{{ item.name }}</span>
                    <span class="select"></span>
                </li>
            </ul>
            <div class="bottom">
                <span class="cancel" @click="setOrder('cancel')">取消</span>
                <span class="confirm" @click="setOrder('confirm')">确认</span>
            </div>
        </div>
    </van-popup>
    <!-- 设置套餐服务 -->
    <div class="setMeal" v-if="setMealType">
        <div class="content">
            <img class="content-close" @click="closeSetMeal()" src="./img/close.png" alt="" />
            <div class="back" v-if="setMealType == 3 || setMealType == 4" @click="setMealType = 2"><img src="./img/back.png" alt=""></div>
            <div class="top-tips" v-show="setMealType == 4">已合并{{orderList.length}}个订单，以下选择将同步应用至合并的订单</div>
            <div :class="['top',{'height':setMealType != 3}]">
                <p class="title">{{setMealTitle()}}</p>
            </div>
            <!-- 合并订单 -->
            <div class="merge-box" v-if="setMealType == 2">
                <div :class="['item-box',{'height':originalOrderList.length>4}]">
                    <div class="item" v-for="item in originalOrderList" :key="item.id">
                        <div class="item-left">
                            <p>平台接单服务({{item.buy_month}}个月)</p>
                            <p>{{item.id}}</p>
                        </div>
                        <div class="item-right">
                            <p class="item-right-error" v-if="item.sn=='' || !item.service_type">未选用</p>
                            <div class="item-right-info" v-else>
                                <p class="item-right-info-type">{{item.service_type==1?'备用机服务':'保修服务'}}</p>
                                <p class="item-right-info-sn">打印机：{{item.sn}}</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="merge-btn" @click="openOnceService(3)">去逐一选用服务</div>
                <!-- <p class="merge">想全部合并使用至一台打印机？ <em @click="openOnceService(4)">点我合并</em> </p> -->
                <p class="tips">注：一台打印机最多可享受保修赠送1年，超过1年则不可再享受保修赠送服务。请谨慎选择，点击确定后将不可变更。</p>
            </div>
            <!-- 单个订单/多个订单 -->
            <div class="other" v-if="setMealType == 1 || setMealType == 3 || setMealType == 4">
                <div :class="['center',{'flow':setMealType == 3}]">
                    <!-- 单个订单 -->
                    <div class="once" v-if="setMealType == 1 || setMealType == 4">
                        <div :class="['input',{'error':errorType==1}]">
                            <input class="it" type="text" placeholder="输入打印机编号 (打印机底部标贴可查)" maxlength="10" @input="handOnceSn()" v-model="serviceSn" @click.stop="showSnList(1)" oninput="value=value.replace(/[^\d]/g,'')">
                            <em v-if="errorType==1">{{errorText}}</em>
                            <div class="select-menu" v-if="snList.length>0 && snListStatus">
                                <p v-for="item in snList" :key="item.id" @click.stop="selectSn(item)">
                                    {{ item.sn }}
                                </p>
                            </div>
                            <div class="loading" v-show="!requestBan">
                                查询中
                                <van-loading color="#999" size="20" />
                            </div>
                        </div>
                        <div class="meal">
                            <div :class="['item', { active: _item.checked },{not:_item.id == 2 && exceeding}]" v-for="(_item, index) in snTypeList" :key="_item.id" @click="selectSnType(_item)">
                                <img class="left" :src="require(`./img/icon_${index+1}.png`)" alt="" />
                                <div class="right">
                                    <p>{{ _item.name }}</p>
                                </div>
                            </div>
                            <div class="error-text" v-if="errorType==2">{{ errorText }}</div>
                        </div>
                    </div>
                    <!-- 多个订单 -->
                    <div class="more" v-if="setMealType == 3">
                        <div :class="['more-content',{ 'error-item':_item.errorSnText!=''|| _item.errorServiceText!=''}]" v-for="(_item,_index) in orderList" :key="_item.id">
                            <div :class="['input',{'error':_item.errorSnText!=''}]">
                                <input type="text" placeholder="输入打印机编号 (打印机底部标贴可查)" maxlength="10" v-model="_item.sn" @input="handMoreSn($event,_item)" @click.stop="showSnList(2,_item)" oninput="value=value.replace(/[^\d]/g,'')">
                                <em v-show="_item.errorSnText!=''">{{_item.errorSnText}}</em>
                                <div class="select-menu" v-if="snList.length>0 && _item.snListStatus">
                                    <p v-for="item in snList" :key="item.id" @click.stop="selectSn(item,_item)">
                                        {{ item.sn }}
                                    </p>
                                </div>
                                <div class="loading" v-show="!_item.loading">
                                    查询中
                                    <van-loading color="#999" size="20" />
                                </div>
                            </div>
                            <div class="item-meal">
                                <div :class="['item', { active: item.id ==_item.service_type },{error:_item.errorServiceText!=''},{not:item.id == 2 && _item.exceeding}]" v-for="(item, index) in snTypeList" :key="item.id" @click="selectSnType(item,_item)">
                                    <img class="left" :src="require(`./img/icon_${index+1}.png`)" alt="" />
                                    <div class="right">
                                        <p>{{ item.name }}</p>
                                    </div>
                                </div>
                                <em class="error-text" v-show="_item.errorServiceText!=''">{{_item.errorServiceText}}</em>
                            </div>
                            <div class="icon">
                                订单{{_index+1}}
                            </div>
                        </div>
                    </div>
                    <div class="service-content">
                        <p>1、本服务仅支持一台打印机可享，请谨慎填写，一经确定，不可修改。</p>
                        <p>2、本服务以所属套餐成功绑定店铺时开始生效，请及时选择套餐以免造成不必要的损失。</p>
                        <p>3、一台打印机最多可获取保修期1年。</p>
                        <p>4、打印机服务：赠送保修期 <span @click="viewServices(2)">(查看服务详情)</span></p>
                    </div>
                </div>
            </div>
            <div class="bottom">
                <div :class="['btn',{not:btnConfirmStatus}]" @click="confirmMeal()">确定</div>
            </div>
        </div>
    </div>
    <!-- 客服 -->
    <div class="consult" v-clipboard:copy="phone" v-clipboard:success="openConsult">
        <img src="./img/consult.png" alt="">
        <span>客服</span>
    </div>
</div>
</template>

<script>
import request from "@util/request";
import {
    getRequest,
    apiUrl,
    FormatDateTime,
    FormatDate,
    funDate,
    yearFormatDate,
    getMonthDay
} from "@util/index";
import qs from "qs";
import loading from "@com/loading/index.vue";
import Dialog from "@com/Dialog/index.vue";
import {
    Toast
} from 'vant';
export default {
    data() {
        return {
            consultPop: false,
            phone: "020-23398726",
            param: {},
            shops: [],
            originalShops: [],
            message_count: 0,
            pid: "2",
            tips: 1,
            isLoading: false,
            isDialog: false,
            showVan: false,
            printtype: null,
            setList: [{
                    name: "打印，自动确认订单",
                    printtype: 0,
                },
                {
                    name: "打印,不确认订单",
                    printtype: 1,
                },
                {
                    name: "不自动打印",
                    printtype: 2,
                },
            ],
            clickItem: {
                poiid: null,
            },
            dialogConfig: null,
            typeList: [{
                name: "全部",
                poiid: 0,
                checked: true
            }, {
                name: "已授权",
                poiid: 1,
                checked: false
            }, {
                name: "未授权",
                poiid: 2,
                checked: false
            }],
            snTypeList: [
                // {
                //     name: "备用机服务",
                //     checked: false,
                //     id: 1,
                // },
                {
                    name: "保修服务（赠送打印机6个保修服务）",
                    checked: false,
                    id: 2,
                },
            ],
            setMealType: false, //1=>单个订单  2=>合并订单/逐个选择  3=>多个订单 4=>合并成一个
            orderList: [], //订单列表
            originalOrderList: [], //原有的数据
            confirmList: [],
            serviceType: null, //选中的套餐
            serviceSn: "", //sn号
            errorText: "", //错误提示
            errorType: null, //错误类型
            snListRequest: true,
            snList: [], //sn列表
            snListStatus: false, //是否显示打印机列表
            exceeding: false, //是否可点击保修服务
            requestBan: true, //禁止多次请求
            limit: true,
            closeSetMealPop: false,
            confirmFlag: false, //是否确定提交
            clickSnItem: {}, //点击的sn
        };
    },
    filters: {
        formatDate: function (value) {
            return FormatDateTime(parseInt(value), 0);
        },
    },
    components: {
        loading,
        Dialog,
    },
    computed: {
        // 判断是否可以提交订单
        btnConfirmStatus() {
            let flag = true
            if (this.setMealType == 2) {
                this.orderList.map(item => {
                    if (item.sn != '' && item.service_type != null && !item.exceeding) {
                        flag = false
                    }
                })
            } else if (this.setMealType == 3 || this.setMealType == 1) {
                flag = false
            }
            return flag
        },
    },
    methods: {
        // 客服弹窗
        openConsult() {
            this.consultPop = true
            this.isDialog = true;
            this.dialogConfig = {
                confirm: "关闭",
            };
        },
        // 打印机设置按钮判断(暂时去掉票据设置的判断)
        setPrintBtnStatus(item) {
            let obj = {
                href: "javascript:void(0);",
                class: "box vc hc shop-btn"
            }
            if (item.poiid && !item.sn && item.expire_time != 0 && !this.out_date(item.expire_time)) {
                obj.class += " active"
            }
            if (item.is_white != 1) {
                if (item.is_shenhe == 3 && item.expire_time != 0) {
                    obj.class += " not"
                } else {
                    obj.href = `addShop.php?pro=1&sid=${item.sid}&pid=${item.pid}`
                }
            } else {
                if (item.is_shenhe == 3) {
                    obj.class += " not"
                } else {
                    obj.href = `addShop.php?pro=1&sid=${item.sid}&pid=${item.pid}`
                }
            }
            // 强制停止时不能选择打印机设置
            // if (item.is_stop_service == 1) {
            //     obj.class += " not"
            //     obj.href = `javascript:void(0);`
            // }
            // if (item.poiid && !item.sn) {
            //     obj.class += " animation"
            // }
            return obj
        },
        // 开通服务按钮判断
        openBtnStatus(item) {
            let flag = false
            if ((item.is_white != 1 && item.is_shenhe != 3) || (this.out_date(item.expire_time) && item.is_shenhe == 3)) {
                flag = true
            }
            if (item.is_white == 1 && item.is_shenhe == 3) {
                flag = false
            }
            return flag
        },
        // 服务状态判断
        serverStatus(item) {
            let obj = {
                class: "danger",
                text: ""
            }
            if (item.is_white == 1) {
                if (item.is_shenhe == 3) {
                    obj.text = '授权失效'
                } else {
                    obj.text = '使用中'
                    obj.class = ''
                }
            } else if (!item.poiid) {
                obj.text = '未授权'
                obj.class = ''
            } else if ((this.out_date(item.expire_time) && item.is_white == 0)) {
                obj.text = '已到期'
            } else if (item.is_shenhe == 3) {
                obj.text = '授权失效'
            } else if (!this.out_date(item.expire_time) && item.buy_type == 1) {
                obj.text = '使用中'
                obj.class = ''
            }
            if (item.is_stop_service == 1) {
                obj.text = '服务暂停'
                obj.class = 'danger'
            }
            return obj
        },
        // 提示显示判断
        tipsStatus(item) {
            let obj = {
                class: "not-poiid",
                text: "",
                href: "javascript:void(0);",
            }
            if (item.is_stop_service == 1) {
                obj.text = ""
            } else if (!item.poiid && item.buy_type == 3 && item.is_white == 0) {
                obj.text = '优惠服务仅支持授权新店铺，请尽快授权！'
            } else if (!item.poiid) {
                obj.text = '未完成授权，请及时授权店铺'
            } else if ((this.out_date(item.expire_time) && item.is_white == 0)) {
                obj.text = '服务已过期'
                obj.class = 'out-date'
            } else if (this.fastExpiration(item) && item.is_white == 0) {
                obj.text = '服务即将过期，请及时续费'
                obj.class = 'stop-service'
            } else if (item.is_shenhe == 3) {
                obj.class = 'stop-service'
                obj.text = '店铺授权已失效'
            } else if (item.poiid && !item.sn) {
                obj.text = '第3步：设置打印小票模板并保存完成'
                obj.href = `addShop.php?pro=1&sid=${item.sid}&pid=${item.pid}`
            }
            return obj
        },
        // 接单状态判断
        orderReceiving(item) {
            let obj = {
                class: "status-c",
                text: "",
            }
            if (+item.printtype == 0) {
                obj.text = '打印，自动确认订单'
            } else if (+item.printtype == 1) {
                obj.text = '打印,不确认订单'
            } else {
                obj.text = '不自动打印'
            }
            if ((this.out_date(item.expire_time) || item.is_shenhe == 3) && item.is_white != 1 && item.expire_time != 0) {
                obj.class = 'status-c not'
            }
            // 白名单并且授权失效
            if (item.is_white == 1 && item.is_shenhe == 3) {
                obj.class = 'status-c not'
            }
            if (item.is_stop_service == 1) {
                obj.class = 'status-c not'
            }
            return obj
        },
        // 合并/单个选用---手动输入sn的逻辑
        handOnceSn() {
            this.snListStatus = false
            if (this.serviceSn.length > 8) {
                // 输入的sn与sn列表相同时
                if (this.snList.some(i => i.sn === this.serviceSn)) {
                    this.errorText = ""
                    this.exceeding = false
                    this.errorType = null
                    this.serviceType = null
                    this.snTypeList.map((i) => {
                        i.checked = false
                    })
                    let currentSn = this.snList.filter(i => i.sn == this.serviceSn)[0]
                    if (this.out_date(currentSn.expire_time) || (this.getServiceMonth(currentSn) + +this.orderList[0].repair_month > 12)) {
                        this.exceeding = true
                    } else {
                        this.exceeding = false
                    }
                    //合并订单时，延长保修时间不能超过12个月
                    if (this.setMealType == 4 && currentSn.stat_month + (+this.countTotal(this.orderList, 'repair_month')) > 12) {
                        this.exceeding = true
                    }
                    if (this.setMealType == 4) {
                        this.orderList.map(i => {
                            i.sn = currentSn.sn
                        })
                    }
                } else {
                    // 订单号大于3个时不能选择保修服务,无需请求,节省资源
                    if (this.orderList.length > 2) {
                        this.exceeding = true
                        return
                    }
                    if (this.requestBan) {
                        this.requestBan = false
                        request({
                            method: "POST",
                            url: apiUrl,
                            headers: {
                                "Content-Type": "application/x-www-form-urlencoded",
                            },
                            data: {
                                action: "ShopService_isExtendWarranty",
                                sn: this.serviceSn,
                            },
                            transformRequest: [
                                function (data) {
                                    return qs.stringify(data);
                                },
                            ],
                        }).then(res => {
                            this.requestBan = true
                            let data = res.data.data
                            if (data.expire_time == 0 || data.stat_month >= 12) {
                                this.errorType = 1
                                this.errorText = "您输入的打印机暂未绑定激活，请先绑定激活打印机。"
                                this.exceeding = true
                            } else {
                                this.errorText = ""
                                this.exceeding = false
                                this.errorType = null
                            }
                        })
                    }
                }

            }
        },
        // 逐一选用---手动输入sn的逻辑
        handMoreSn(event, item) {
            let snValue = event.target.value
            item.snListStatus = false
            if (snValue.length > 8 && !this.snList.some(i => i.sn == item.sn) && item.loading) {
                item.loading = false
                request({
                    method: "POST",
                    url: apiUrl,
                    headers: {
                        "Content-Type": "application/x-www-form-urlencoded",
                    },
                    data: {
                        action: "ShopService_isExtendWarranty",
                        sn: snValue,
                    },
                    transformRequest: [
                        function (data) {
                            return qs.stringify(data);
                        },
                    ],
                }).then((res) => {
                    let data = res.data.data
                    item.loading = true
                    if (data.expire_time == 0 || data.stat_month >= 12) {
                        item.exceeding = true
                        if (data.expire_time == 0)
                            item.errorSnText = "您输入的打印机暂未绑定激活，请先绑定激活打印机。"
                        item.expire_time = 0
                        item.errorServiceText = ""
                        if (item.service_type == 2) {
                            item.service_type = null
                            this.snTypeList.map((i) => {
                                i.checked = false;
                            });
                        }
                    } else {
                        item.exceeding = false
                        item.expire_time = data.expire_time
                        item.errorSnText = ""
                    }
                    // 需要遍历所有项,判断修改延长保修是否可选中
                    this.getEqualArr(this.orderList, item)
                })
            }
            // 当输入的sn号在原先的sn列表中含有时,需要判断所有数据是否可选中延长保修
            if (this.snList.some(i => i.sn == item.sn)) {
                item.expire_time = 1
                item.errorSnText = ""
                let currentSn = this.snList.filter(i => i.sn == item.sn)[0]
                if (this.out_date(currentSn.expire_time) || this.getServiceMonth(currentSn) >= 12) {
                    item.exceeding = true
                } else {
                    this.getEqualArr(this.orderList, item)
                }
            }
        },
        openOnceService(type) {
            this.setMealType = type
            if (type == 3) {
                // this.orderList = JSON.parse(JSON.stringify(this.originalOrderList))
            } else {
                this.snTypeList.map(item => {
                    if (item.id == this.serviceType) {
                        item.checked = true
                    } else {
                        item.checked = false
                    }
                })
            }
        },
        closeSetMeal() {
            let flag = false
            this.orderList.map(item => {
                if (item.sn != '' && !item.exceeding && item.service_type != null) {
                    flag = true
                }
            })
            if ((this.serviceSn != '' && this.serviceType != null) || flag) {
                this.isDialog = true;
                this.dialogConfig = {
                    title: "关闭弹窗将不保存已填写信息，确认退出？",
                    confirm: "确定",
                    cancel: "取消"
                };
                this.closeSetMealPop = true
                return
            }
            this.setMealType = null
            this.serviceSn = ""
            this.serviceType = null
            this.confirmList = []
            this.snTypeList[0].checked = false
            this.closeSetMealPop = false
            this.exceeding = false
            this.errorText = ""
            this.errorType = null
        },
        // 获取所有订单的延长服务时间
        getServiceMonth(snItem) {
            let month = +snItem.stat_month
            this.orderList.map(i => {
                if (i.sn == snItem.sn && i.service_type == 2) {
                    month += +i.repair_month
                }
            })
            return +month
        },
        // 判断服务状态可选
        getEqualArr(arr, currentItem) {
            // 获取相同的sn的数组
            let resArr = []
            let currentArr = [...arr]
            while (currentArr.length !== 0) {
                let list = currentArr.shift()
                let arr = [list]
                for (let i = 0; i < currentArr.length; i++) {
                    if (currentArr[i].sn === list.sn) {
                        arr = arr.concat(currentArr.splice(i, 1))
                        i--
                    }
                }
                resArr.push(arr)
            }
            // 是否可以选延长保修判断
            resArr.map(j => {
                let currentSn = j.filter(i => i.service_type == 2)
                j.map((i, index) => {
                    if (currentSn.length >= 2 && i.service_type != 2) {
                        i.exceeding = true
                    } else {
                        i.exceeding = false
                    }
                    if (i.expire_time == 0) {
                        i.exceeding = true
                    }
                    // 满24个月的sn不能选延保服务
                    this.snList.map(_i => {
                        if (_i.sn == i.sn && (this.getServiceMonth(_i) + +currentItem.repair_month > 12 && i.service_type != 2)) {
                            i.exceeding = true
                        }
                        // 过期
                        if (this.out_date(_i.expire_time) && _i.sn == i.sn) {
                            //订单时间减去打印机时间一年内也可以选择延保服务
                            if ((+i.created_at - +_i.first_bind_time <= yearFormatDate()) && (this.getServiceMonth(_i) + +currentItem.repair_month <= 12)) {
                                i.exceeding = false
                            }
                            if (+i.created_at - +_i.first_bind_time > yearFormatDate()) {
                                i.exceeding = true
                            }
                            // 当前订单时间 + 当前选中服务的时间 > 绑定时间+23个月15天 不给选择
                            let created_at = +i.created_at + 60 * 60 * 24 * getMonthDay(i.created_at, this.getServiceMonth(_i))
                            if (created_at > +_i.first_bind_time + +yearFormatDate() && i.service_type != 2) {
                                i.exceeding = true
                            }
                        } else if (!this.out_date(_i.expire_time) && _i.sn == i.sn) {
                            // 未过期
                            let expire_time = +_i.expire_time + 60 * 60 * 24 * getMonthDay(_i.expire_time, this.getServiceMonth(_i))
                            if (expire_time > +_i.first_bind_time + +yearFormatDate() && i.service_type != 2) {
                                i.exceeding = true
                            }
                        }
                    })
                })
            })
            let newOrderList = [].concat(...resArr);
            this.orderList.map(i => {
                i = newOrderList.filter(j => j.id == i.id)
            })
        },
        // 选择打印机
        selectSn(item, _item) {
            // 逐一选用
            if (_item) {
                this.snTypeList.map(i => {
                    i.checked = false
                })
                if ((item.sn != _item.sn && _item.sn != '') || _item.sn == '') {
                    _item.service_type = null
                }
                _item.sn = item.sn
                _item.snListStatus = false
                // 遍历数据同一sn号超过24小时的保修服务时不给选中
                this.getEqualArr(this.orderList, _item)
            } else {
                this.clickSnItem = item
                this.serviceSn = item.sn
                this.snListStatus = false
                this.serviceType = null
                this.snTypeList.map((i) => {
                    i.checked = false
                })
                if (this.out_date(item.expire_time) || (this.getServiceMonth(item) + +this.orderList[0].repair_month > 12)) {
                    this.exceeding = true
                } else {
                    this.exceeding = false
                }
                // 订单时间减去打印机时间一年内也可以选择延保服务
                if (this.out_date(item.expire_time)) {
                    if ((+this.orderList[0].created_at - +item.first_bind_time <= yearFormatDate()) && (this.getServiceMonth(item) + +this.orderList[0].repair_month <= 12)) {
                        this.exceeding = false
                    }
                }

                //合并订单时，延长保修时间不能超过24小时
                if (this.setMealType == 4 && item.stat_month + (+this.countTotal(this.orderList, 'repair_month')) > 12) {
                    this.exceeding = true
                }
                if (this.setMealType == 4) {
                    this.orderList.map(i => {
                        i.sn = item.sn
                    })
                }
            }
        },
        // 选择套餐类型
        selectSnType(item, _item) {
            //  单个订单/合并订单，当延长保修时间超过12个月不能点击
            if (this.exceeding && (this.setMealType == 1 || this.setMealType == 4) && item.id == 2) {
                return
            }
            // 逐个订单时，当延长保修时间超过12个月不能点击
            if (this.setMealType == 3 && _item.exceeding && item.id == 2) {
                return
            }
            // 单个订单/合并订单类型选择
            if (this.setMealType != 3) {
                this.serviceType = item.id
            }
            this.snTypeList.map((i) => {
                if (i.id == item.id) {
                    i.checked = true;
                } else {
                    i.checked = false;
                }
                if (this.setMealType == 3) {
                    _item.errorServiceText = ""
                }
            });
            if (this.setMealType == 1 || this.setMealType == 4) {
                this.errorType = null
            }
            if (this.setMealType == 3) {
                _item.service_type = item.id
                // 遍历数据同一sn号超过24小时的保修服务时不给选中
                this.getEqualArr(this.orderList, _item)
            }
            if (this.setMealType == 4) {
                this.orderList.map(i => {
                    i.service_type = item.id
                })
            }
        },
        // 计算对象数组中某个属性合计
        countTotal(arr, keyName) {
            let $total = 0;
            $total = arr.reduce(function (total, currentValue) {
                return currentValue[keyName] ? (+total + +currentValue[keyName]) : +total;
            }, 0);
            return $total;
        },
        // 是否展示打印机列表
        showSnList(type, item) {
            if (type == 2) {
                item.errorSnText = ''
                item.snListStatus = !item.snListStatus
            } else {
                this.errorText = '';
                this.errorType = null
            }
            this.snListStatus = !this.snListStatus;
            if (this.snListRequest) {
                this.snListRequest = false
                this.initSnList()
            }
        },
        //验证数据
        verification() {
            if (this.setMealType == 1 || this.setMealType == 4) {
                if (this.serviceSn == '' || !(/^\d{9,10}/.test(this.serviceSn))) {
                    this.errorText = "打印机编号输入错误；"
                    this.errorType = 1
                    return false
                }
                if (this.serviceType == null && this.serviceSn != '' && this.exceeding) {
                    this.errorType = 2
                    if (this.getServiceMonth(this.clickSnItem) + +this.orderList[0].repair_month > 12) {
                        this.errorText = "此打印机延长保修已超12个月，不再享受延长保修;"
                        return false
                    }
                    if (this.out_date(this.clickSnItem.expire_time)) {
                        if (+this.orderList[0].created_at - +this.clickSnItem.first_bind_time > yearFormatDate()) {
                            this.errorText = "此打印机使用超过2年，不可享受延长保修;"
                            return false
                        }
                    }
                } else if (this.serviceType == null) {
                    this.errorType = 2
                    this.errorText = "请选择打印机服务套餐"
                    return false
                }
            } else if (this.setMealType == 3) {
                let flag = true
                this.orderList.map(item => {
                    if (item.sn == '' || !(/^\d{9,10}/.test(item.sn))) {
                        item.errorSnText = "打印机编号输入错误；"
                        flag = false
                    }
                    if (item.service_type == null && !item.exceeding) {
                        item.errorServiceText = "请选择打印机服务套餐!"
                        flag = false
                    }
                    if (item.sn != '') {
                        let currentSn = this.snList.filter(i => i.sn == item.sn)[0]
                        if (this.getServiceMonth(currentSn) + +item.repair_month > 12 && item.exceeding) {
                            item.errorServiceText = "此打印机延长保修已超12个月，不再享受延长保修;"
                            flag = false
                        }
                        if (this.out_date(currentSn.expire_time)) {
                            if (+item.created_at - +currentSn.first_bind_time > yearFormatDate()) {
                                item.errorServiceText = "您的打印机已达到最大延长保修期，不可享受延长保修;"
                                flag = false
                            }
                            let created_at = +item.created_at + 60 * 60 * 24 * getMonthDay(item.created_at, this.getServiceMonth(currentSn))
                            if (created_at > +currentSn.first_bind_time + +yearFormatDate() && item.service_type!=2) {
                                item.errorServiceText = "您的打印机已达到最大延长保修期，不可享受延长保修;"
                                flag = false
                            }
                        } else {
                            let expire_time = +currentSn.expire_time + 60 * 60 * 24 * getMonthDay(currentSn.expire_time, this.getServiceMonth(currentSn))
                            if (expire_time > +currentSn.first_bind_time + +yearFormatDate() && item.service_type!=2) {
                                item.errorServiceText = "您的打印机已达到最大延长保修期，不可享受延长保修;"
                                flag = false
                            }
                        }
                    }
                })
                if (!flag) {
                    this.$nextTick(() => {
                        document.querySelector(".error-item").scrollIntoView({
                            block: "center",
                            behavior: "smooth"
                        });
                    });
                }
                return flag
            } else if (this.setMealType == 2) {
                let flag = true
                this.orderList.map(item => {
                    if (item.sn == '' || !item.service_type) {
                        flag = false
                    }
                })
                return flag
            }
            return true
        },
        // 确定选择服务按钮
        confirmMeal() {
            if (this.setMealType == 3) {
                if (!this.verification()) {
                    // 判断是否存在有效订单号
                    let flag = false
                    this.confirmFlag = true
                    this.orderList.map(item => {
                        if (item.sn != '' && item.service_type != null && !item.exceeding) {
                            flag = true
                        }
                    })
                    if (flag) {
                        this.isDialog = true;
                        this.dialogConfig = {
                            title: "您有订单暂未设置套餐赠送的打印机延保服务，是否确定？",
                            details: `<p style="color:#999">提交后，未设置服务的订单可在“飞鹅订单助手 - 我的 - 购买记录 - 订单详情”去设置。</p>`,
                            cancel: "返回",
                            confirm: "确定",
                        };
                    }
                    return
                }
            } else if (this.setMealType == 1) {
                if (!this.verification()) return
            }
            if (this.setMealType == 4 || this.setMealType == 3) {
                this.originalOrderList = JSON.parse(JSON.stringify(this.orderList))
                // 当合并过时再次合并时需要遍历数据，不然数据不会自动更新
                if (this.setMealType == 4 && this.serviceSn != "" && this.serviceType != null) {
                    this.originalOrderList.map(item => {
                        item.sn = this.serviceSn
                        item.service_type = this.serviceType
                        if (item.sn != '' && item.service_type != null && !item.exceeding && !this.confirmList.some(j => j.id == item.id)) {
                            this.confirmList.push(item)
                        }
                    })
                    this.orderList = JSON.parse(JSON.stringify(this.originalOrderList))
                }
                if (this.setMealType == 3) {
                    this.confirmList = []
                    this.orderList.map(item => {
                        if (item.sn != '' && item.service_type != null && !item.exceeding && !this.confirmList.some(j => j.id == item.id)) {
                            this.confirmList.push(item)
                        }
                    })
                }
                this.setMealType = 2
                return
            }
            let params = {
                action: "ShopService_setSnServiceType",
                content: [],
                pid: this.pid,
                third_id: this.clickItem.poiid
            }
            this.orderList.map(i => {
                let obj = {
                    orderId: i.id,
                    sn: i.sn,
                    service_type: i.service_type
                }
                if (this.setMealType == 4 || this.setMealType == 1) {
                    obj.sn = this.serviceSn
                    obj.service_type = this.serviceType
                }
                if (this.setMealType == 2 && i.sn != '' && i.service_type != null && !i.exceeding) {
                    params.content.push(obj)
                }
                if (this.setMealType == 1) {
                    params.content.push(obj)
                }
            })
            params.content = JSON.stringify(params.content)
            if (this.limit) {
                this.limit = false
                request({
                    method: "POST",
                    url: apiUrl,
                    headers: {
                        "Content-Type": "application/x-www-form-urlencoded",
                    },
                    data: params,
                    transformRequest: [
                        function (data) {
                            return qs.stringify(data);
                        },
                    ],
                }).then((res) => {
                    if (res.data.ret == 0) {
                        Toast({
                            message: '设置硬件套餐成功！',
                            position: 'top',
                            onClose: () => {
                                this.setMealType = null
                                this.limit = true
                                this.initSetMeal()
                            }
                        })
                    } else {
                        this.limit = true
                        Toast({
                            message: res.data.msg,
                            position: 'top',
                        })
                    }
                });
            }
        },
        // 设置服务弹窗标题
        setMealTitle() {
            let text = ""
            switch (this.setMealType) {
                case 1:
                    text = "您有已购订单未选用硬件服务"
                    break;
                case 2:
                    text = `您有${this.orderList.length}个已购订单未选用硬件服务`
                    break;
                case 3:
                    text = "请逐一选用打印机的服务类型"
                    break;
                case 4:
                    text = "请选用打印机服务类型"
                    break;
                default:
                    break;
            }
            return text
        },
        // 打开服务请求弹窗
        selectMeal(item) {
            this.clickItem = item
            request({
                method: "POST",
                url: apiUrl,
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                },
                data: {
                    action: "ShopService_getNeedServiceOrders",
                    third_id: item.poiid,
                    pid: this.pid
                },
                transformRequest: [
                    function (data) {
                        return qs.stringify(data);
                    },
                ],
            }).then((res) => {
                let _data = res.data
                if (_data.ret == 0) {
                    _data.data.map(item => {
                        item.sn = ""
                        item.service_type = null
                        item.errorSnText = ""
                        item.errorServiceText = ""
                        item.snListStatus = false
                        item.exceeding = false
                        item.loading = true
                    })
                    this.originalOrderList = JSON.parse(JSON.stringify([..._data.data]))
                    this.orderList = [..._data.data]
                    if (this.orderList.length > 1) {
                        this.setMealType = 2
                    } else {
                        this.setMealType = 1
                    }
                }
            });
        },
        // 说明
        viewServices(type) {
            this.isDialog = true;
            let kg = "&nbsp;&nbsp;&nbsp;&nbsp;"
            if (type == 1) {
                this.dialogConfig = {
                    title: "备用机服务说明",
                    details: `
                    <p>${kg}购买一次店铺授权服务则可选择获得单次一台备用机服务；若购买多个店铺授权服务，则可叠加单次使用备用机的数量。备用机服务有效期时长对应所购套餐时长；</p>
                    <p>${kg}1、什么是备用机服务？</p>
                    <p>${kg}备用机服务是指所填打印机在返厂维修时，可申请获取一台由我司原厂提供的打印机作为您的店铺临时备用打印机进行使用，需支付相应的押金费用，押金将在退回备用机后退还。</p>
                    <p>${kg}2、备用机服务期限？</p>
                    <p>${kg}备用机服务有效期以所属套餐成功授权店铺起计算开始时间，到店铺有效期服务周期终止时间终止。备用机服务时长根据用户所购套餐时长对应服务时长；若用户申请退款，则备用机服务时长将根据用户退款信息对应缩减。</p>
                    <p class='red'>* 注：服务过程中，若因人为原因造成备用机损坏，则需要支付相应的维修费用，为免造成不必要的损失，请您文明使用设备，切勿损坏设备。</p>
                    `,
                    confirm: "知道了",
                };
            } else if (type == 2) {
                this.closeSetMealPop = false
                this.confirmFlag = false
                this.dialogConfig = {
                    title: "赠送保修期",
                    details: `
                    <p>${kg}购买一次店铺授权服务可获得一次赠送的增加打印机保修时长套餐的服务，赠送的保修时长服务在对应店铺授权服务有效期内有效；</p>
                    <p>例：购买1年套餐则对应获得为单台打印机增加保修时长6个月赠送服务；</p>
                    <p>${kg}打印机赠送保修服务有效期以所属套餐成功授权店铺起计算开始时间。请在所属套餐授权有效期内6个月前，尽快提交服务所享打印机编号；授权有效期过期，则该赠送服务将自动失效。</p>
                    <p>例：若您在2022年1月1日购买店铺授权服务并成功授权店铺，则赠送保修时长服务有效时间为2022年1月1日到2022年6月1日。</p>
                    <p>${kg}若在购买后未及时设置，则可在 “ 平台店铺管理列表 - 店铺信息卡片 - 硬件服务 ” 或 “ 我的 - 购买记录 - 对应订单详情页 - 硬件套餐：打印机保修服务 -去应用 ” 去进行提交。</p>
                    <p>${kg}您的打印机必须在打印机首次激活时间到购买店铺授权服务的时间之间的间隔不超过2年时间。</p>
                    <p>${kg}若购买多次店铺授权，并选择本服务，您可选择对不同的打印机设置添加保修时长，或对单台打印机叠加保修时长。一台打印机最多可享受12个月保修时长。</p>
                    <p>${kg}若您对保修服务申请了退款，则打印机保修服务时长将根据退款内容对应缩减。</p>
                    <p class='red'>* 注：本服务为购买授权店铺套餐的附赠服务，非付费服务。</p>`,
                    confirm: "知道了",
                };
            }
        },
        isRenew(item) {
            if (item.is_shenhe == 3 && !this.out_date(item.expire_time)) {
                return `buyService.php?is_renewal=0&epoid=${item.shopid}`
            } else {
                return `buyService.php?is_renewal=1&epoid=${item.shopid}`
            }
        },
        notPoiid(item) {
            request({
                method: "POST",
                url: apiUrl,
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                },
                data: {
                    action: "ShopService_getOrderInfoByEpoid",
                    epoid: item.shopid,
                    pid: this.pid
                },
                transformRequest: [
                    function (data) {
                        return qs.stringify(data);
                    },
                ],
            }).then((res) => {
                let _data = res.data;
                if (_data.ret == 0) {
                    localStorage.setItem("orderId", _data.data.id)
                    window.location.href = `gotoBind2.php?buyOrderId=${item.shopid}`
                } else {
                    window.location.href = `gotoBind2.php?buyOrderId=${item.shopid}`
                }
            });
        },
        setOrder(type) {
            if (type == "cancel") {
                this.showVan = false;
            } else {
                // 请求
                let data = {
                    method: "POST",
                    url: apiUrl,
                    headers: {
                        "Content-Type": "application/x-www-form-urlencoded",
                    },
                    data: {
                        action: "ShopService_setShopSetting",
                        epoid: this.clickItem.shopid,
                        printtype: this.printtype,
                        pid: this.pid,
                    },
                    transformRequest: [
                        function (data) {
                            return qs.stringify(data);
                        },
                    ],
                };
                request(data).then((res) => {
                    let _data = res.data;
                    if (_data.ret == 0) {
                        this.showVan = false;
                        this.initSetMeal();
                    }
                });
            }
        },
        close_tips() {
            this.tips = false;
        },
        showSet(item, type) {
            if (item.is_stop_service == 1) {
                return
            }
            if ((this.out_date(item.expire_time) || item.is_shenhe == 3) && item.is_white != 1 && item.expire_time != 0) {
                return
            }
            // 白名单授权失效不能接单状态
            if (item.is_shenhe == 3 && item.is_white == 1) {
                return
            }
            this.printtype = item.printtype;
            if (type == "list") {
                this.showVan = true;
                this.clickItem = item;
            }
        },
        // 已过期
        out_date(time) {
            let currenttime = parseInt(new Date().getTime() / 1000);
            if (time == 0) {
                return true
            }
            if (+time < currenttime) {
                return true;
            }
            return false
        },
        // 快过期
        fastExpiration(item) {
            let _time = parseInt(item.expire_time);
            let nowdate = new Date();
            nowdate.setMonth(nowdate.getMonth() + 1);
            let y = nowdate.getFullYear();
            let m = nowdate.getMonth() + 1;
            let d = nowdate.getDate();
            let formatwdate = `${y}-${m}-${d}`;
            if (item.buy_type == 2) {
                if (parseInt(FormatDate(funDate(7))) > _time) {
                    return true
                } else {
                    return false
                }
            } else {
                if (parseInt(FormatDate(formatwdate)) > _time) {
                    return true
                } else {
                    return false
                }
            }
        },
        arrangeData(list) {
            list.map((item, index) => {
                if (!item.poiid) {
                    item.shopname = `美团店铺服务（${item.service_prod_id == 5?'1个月':'12个月'}）`
                }
                if (!item.poiid && this.out_date(item.expire_time) && item.expire_time != 0) {
                    item.showStatus = false
                } else {
                    item.showStatus = true
                }
                if (item.is_white == 1 || (item.is_shenhe == 3 && !this.out_date(item.expire_time))) {
                    item.isWhiteHref = `gotoBind2.php?is_again=1&buyOrderId=${item.shopid}`
                }
            })
            return list
        },
        initSetMeal() {
            let data = {};
            data.action = "User_getShopInfoListAll";
            data.pid = this.param.pid;
            this.isLoading = true;
            request({
                method: "POST",
                url: apiUrl,
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                },
                data: data,
                transformRequest: [
                    function (data) {
                        return qs.stringify(data);
                    },
                ],
            }).then((res) => {
                let data = res.data;
                this.isLoading = false;
                // 优惠服务的数据排到前面
                let list = []
                this.arrangeData(data.data.list).map((item, index) => {
                    if (item.buy_type == 3) {
                        list.unshift(item)
                    } else {
                        list.push(item)
                    }
                })
                this.shops = list;
                this.originalShops = list;
                this.exceeding = false
                this.snListRequest = true
            });
        },
        changeList(item) {
            this.typeList.map(_item => {
                if (_item.poiid == item.poiid) {
                    _item.checked = true
                } else {
                    _item.checked = false
                }
            })
            if (item.poiid == 0) {
                this.shops = this.originalShops
            } else if (item.poiid == 1) {
                this.shops = this.originalShops.filter(item => item.poiid)
            } else {
                this.shops = this.originalShops.filter(item => !item.poiid)
            }
        },
        /**
         * 获取未读消息数
         * */
        getMessage() {
            let data = {};
            data.action = "ShopService_getMessageUnReadCount";
            data.pid = this.param.pid;
            request({
                method: "POST",
                url: apiUrl,
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                },
                data: data,
                transformRequest: [
                    function (data) {
                        return qs.stringify(data);
                    },
                ],
            }).then((res) => {
                this.message_count = res.data.data;
            });
        },
        // 获取订单号信息
        getOrderNums() {
            if (localStorage.getItem("orderId")) {
                request({
                    method: "POST",
                    url: apiUrl,
                    headers: {
                        "Content-Type": "application/x-www-form-urlencoded",
                    },
                    data: {
                        action: "ShopService_checkTryOrderIsFail",
                        orderId: localStorage.getItem("orderId"),
                        pid: this.pid
                    },
                    transformRequest: [
                        function (data) {
                            return qs.stringify(data);
                        },
                    ],
                }).then((res) => {
                    let _data = res.data;
                    if (_data.ret == 0 && _data.data.orderCount > 0) {
                        _data.data.orderList.map(item => {
                            item.sn = ""
                            item.service_type = null
                            item.errorSnText = ""
                            item.errorServiceText = ""
                            item.snListStatus = false
                            item.exceeding = false
                            item.loading = true
                        })
                        this.originalOrderList = JSON.parse(JSON.stringify([..._data.data.orderList]))
                        this.orderList = [..._data.data.orderList]
                        if (_data.data.orderCount > 1) {
                            this.setMealType = 2
                        } else {
                            this.setMealType = 1
                        }
                        this.clickItem.poiid = _data.data.third_shopid
                    }
                    localStorage.removeItem("orderId")
                });
            }
        },
        confirm() {
            this.isDialog = false
            this.consultPop = false
            if (this.setMealType == 3 && this.confirmFlag) {
                this.confirmList = []
                this.setMealType = 2
                this.orderList.map(item => {
                    if (item.sn != '' && item.service_type != null && !item.exceeding && !this.confirmList.some(i => i.id == item.id)) {
                        this.confirmList.push(item)
                    }
                })
                this.originalOrderList = JSON.parse(JSON.stringify(this.orderList))
            }
            if (this.closeSetMealPop) {
                this.setMealType = null
                this.serviceSn = ""
                this.serviceType = null
                this.confirmList = []
                this.snTypeList[0].checked = false
                this.closeSetMealPop = false
            }
        },
        close(type) {
            this.isDialog = false;
            this.consultPop = false
            if (this.param.meituan_save && type == 2) {
                window.location.href = "meituan_help.php"
            }
        },
        getShopErrorMsg() {
            let data = {
                action: "ShopService_getOldShopErrMsg",
                pid: this.pid
            }
            request({
                method: "POST",
                url: apiUrl,
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                },
                data: data,
                transformRequest: [
                    function (data) {
                        return qs.stringify(data);
                    },
                ],
            }).then((res) => {
                let data = res.data.data;
                if (data.length != 0) {
                    let msg = data[0].remark
                    Toast(msg);
                }
            });
        },
        // 获取sn列表
        initSnList() {
            let data = {
                method: "POST",
                url: apiUrl,
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                },
                data: {
                    action: "ShopService_getPrintListByUid",
                },
                transformRequest: [
                    function (data) {
                        return qs.stringify(data);
                    },
                ],
            };
            request(data).then((res) => {
                let _data = res.data;
                if (_data.ret == 0) {
                    this.snList = _data.data
                    this.snList.map(item => {
                        item.type = "sn"
                    })
                }
            });
            this.$nextTick(() => {
                document.addEventListener("click", (e) => {
                    if (!e.target.classList.contains("it")) {
                        this.snListStatus = false
                    }
                });
            });
        },
        initPage() {
            if (this.param.meituan_save) {
                this.dialogConfig = {
                    title: "设置成功！已无需再去商家后台设置，请等待新来单即可打印。",
                    details: `<div class="ipt-tips">
                                <div class="top">
                                    <em></em>
                                    <h1>重要提醒</h1>
                                </div>
                                <ul class="content">
                                    <li>为防止“商家PC客户端”的自动接单，而导致打印机漏打订单的可能。我们建议您在安装了“美团商家PC客户端”的电脑，<em>关闭“本台电脑自动接单”</em>的功能</li>
                                    <li>如果有多台电脑安装了“美团商家PC客户端”，都需要<em>全部关闭</em>，，否则依然会存在有电脑抢单的情况。</li>
                                    <li>如果登录“美团商家PC客户端”时，看到有弹窗提示问是否需要开启自动接单，请选择<em>“暂不设置”</em></li>
                                </ul>
                            </div>`,
                    cancel: "查看如何设置",
                    confirm: "知道了",
                };
                this.isDialog = true;
            }
        }
    },
    mounted() {
        this.param = getRequest();
        this.initPage();
        this.initSetMeal();
        this.getMessage();
        this.getShopErrorMsg();
    },
};
</script>

<style lang="less" scoped>
@import "index.less";
</style>
